package com.ecb.business.service.impl;

import chainmaker.sdk.demo.ChainConfig;
import com.ecb.business.dto.chain.HealthCheckDTO;
import com.ecb.business.service.HealthCheckService;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.chainmaker.sdk.config.ChainClientConfig;
import org.chainmaker.sdk.config.SdkConfig;
import org.springframework.stereotype.Service;

import static chainmaker.sdk.demo.InitClient.chainClient;
import static chainmaker.sdk.demo.InitClient.inItChainClient;

@Service
public class HealthCheckServiceImpl implements HealthCheckService {

    @Override
    @SneakyThrows
    public boolean doHealthCheck(HealthCheckDTO healthCheckDTO) {
        SdkConfig sdkConfig = new SdkConfig();
        ChainClientConfig chainClientConfig = healthCheckDTO.getChainClientConfig();
        sdkConfig.setChainClient(chainClientConfig);
        sdkConfig.setChain_client(chainClientConfig);
        inItChainClient(sdkConfig);
        return !StringUtils.isEmpty(ChainConfig.getChainConfig(chainClient));
    }
}
